import subprocess
import sys

from PyQt6.QtWidgets import QApplication

from common.InitWindow import InitWindow
from common.MainWindow import MainWindow


class PhoneTools:
    def check_adb(self):
        """
        启动前验证是否有adb环境，如果没有跳转到InitWindow进行初始化
        :return:
        """
        app = QApplication(sys.argv)

        if self._is_adb_installed():
            main_ui = MainWindow()
            main_ui.show()
        else:
            adb_ui = InitWindow() 
            adb_ui.show()
        sys.exit(app.exec())

    def _is_adb_installed(self):
        try:
            subprocess.run(['adb', 'version'], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            return True
        except FileNotFoundError as e:
            return False


if __name__ == "__main__":
    PhoneTools().check_adb()
